//
//  main.m
//  5999
//
//  Created by Macbook on 16-5-9.
//  Copyright (c) 2016年 cmj. All rights reserved.
//
//
//  main.m
//  5.9.1
//
//  Created by Macbook on 16-5-9.
//  Copyright (c) 2016年 cmj. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    
    @autoreleasepool {
        
        // insert code here...
        NSString *path = @"/Users/mac1/Desktop/syl/syl";
        NSError  *err;
        NSString *mac1=[[NSString  alloc ] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&err];
        if (err !=nil ) {
            NSLog (@"%@",err);
        }
        NSLog (@"%@",mac1);
        NSArray *arr =[mac1 componentsSeparatedByString:@"\n"];
        for (NSString *line in arr ) {
            if ([line hasPrefix:@"BEGIN"]) {
                NSLog(@"开始一条新的记录");
            }
            if([line hasPrefix:@"END"]) {
                NSLog(@"这条记录结束了");
            }
            if ([line hasPrefix:@"tel"]) {
                NSLog(@"找到一条电话记录 !  %@",line);
                NSArray *tels = [line componentsSeparatedByString:@";"];
                NSString *last = tels.lastObject;
                NSInteger len = last.length;
                len -= 5;
                last = [last substringFromIndex:5];
                NSLog (@"tel:%@",last);
            }
            if ([line hasPrefix:@"FN"]) {
                NSLog(@"找到一个fn，也就是姓名:%@",line);
                NSArray *names = [line componentsSeparatedByString:@":"];
                NSString *name = names.lastObject;
                name = [name stringByReplacingOccurrencesOfString:@"="  withString:@"%"];
                name =name.stringByRemovingPercentEncoding;
                NSLog (@"name:%@",name);
            }
        }
        
    }
    return 0;
}

